from django.db import models
from django.utils import timezone


class AssetsType(models.Model):
    name = models.CharField(max_length=32, unique=True, verbose_name="类型名称")

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '资产类型'
        verbose_name_plural = verbose_name
        ordering = ['id']


class Location(models.Model):
    name = models.CharField(max_length=32, unique=True, verbose_name="地点")

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '资产地点'
        verbose_name_plural = verbose_name
        ordering = ['id']

class Assets(models.Model):
    AssetsStatusChoices = (
        (0, '闲置'),
        (1, '使用中'),
        (2, '转交'),
    )

    assetsId = models.CharField(max_length=16, unique=True, verbose_name="资产序号")
    serviceCode = models.CharField(max_length=16,  verbose_name="服务代码")
    asstesType = models.ForeignKey(to=AssetsType,on_delete=models.PROTECT,verbose_name="类型名称")
    assetsName = models.CharField(max_length=64,verbose_name="资产名称")
    specModel = models.CharField(max_length=256,verbose_name="规格型号")
    assetsStatus = models.PositiveSmallIntegerField(choices=AssetsStatusChoices,default=0,verbose_name="资产状态")
    place = models.ForeignKey(Location,models.PROTECT,verbose_name="存放地点")
    purchaseDate = models.DateTimeField(default=timezone.now,verbose_name="购置日期")
    registerDate = models.DateTimeField(default=timezone.now, verbose_name="登记日期")
    condition = models.CharField(max_length=256,verbose_name="配置情况")


    def __str__(self):
        return "{}({})".format(self.assetsName,self.assetsId)


    class Meta:
        verbose_name = '资产'
        verbose_name_plural = verbose_name
        ordering = ['id']



























































